package com.example.peibei.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;
import com.dingtao.common.bean.User;
import com.dingtao.common.core.DataCall;
import com.dingtao.common.core.WDActivity;
import com.dingtao.common.core.exception.ApiException;
import com.dingtao.common.util.SPUtils;
import com.dingtao.common.util.UIUtils;
import com.example.peibei.R;
import com.example.peibei.base.SpConstant;
import com.example.peibei.bean.SpUserInfoCall;
import com.example.peibei.service.presenter.UserInfoPresenter;
import com.example.peibei.ui.fragment.MeFragment;
import com.example.peibei.ui.utils.LevelImage;

import butterknife.BindView;
import butterknife.OnClick;

public class RealNameActivity extends WDActivity {
    @BindView(R.id.bt_submit)
    Button bt_submit;

    private SPUtils spUtils;
    private String token;
    private String mid;
    private boolean identityBool;
    private UserInfoPresenter userInfoPresenter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_real_name;
    }

    @Override
    protected void initView() {
        spUtils = new SPUtils(RealNameActivity.this, SpConstant.USER_TOKEN);
        userInfoPresenter = new UserInfoPresenter(new UserInfoCall());
    }

    @Override
    protected void onResume() {
        super.onResume();
        token = spUtils.getString(SpConstant.USER_TOKEN);
        userInfoPresenter.reqeust("Bearer " + token);
    }

    @OnClick(R.id.iv_back)
    public void back() {
        finish();
    }

    @OnClick(R.id.bt_submit)
    public void submit() {
        if (TextUtils.isEmpty(token)) {
            intent(LoginActivity.class);
            return;
        }
        if (identityBool) {
            UIUtils.showToastSafe("您已经完成认证");
            return;
        }
        intent(IdentityCheckedActivity.class);
        finish();
    }

    class UserInfoCall extends SpUserInfoCall {

        @Override
        public void success(User data, Object... args) {
            super.success(data,args);
            spUtils.putLong(SpConstant.USER_MID, data.getId());
            identityBool = data.isIdentityBool();
            if (identityBool) {
                bt_submit.setText("已完成认证");
            } else {
                bt_submit.setText("开始认证");
            }
        }

        @Override
        public void fail(ApiException e, Object... args) {

        }
    }

    @Override
    protected void destoryData() {

    }
}
